home *** CD-ROM | disk | FTP | other *** search
- Path: obibicut.cs.rmit.edu.au!dale
- From: Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU>
- Newsgroups: comp.lang.ada,comp.lang.c++
- Subject: Re: on OO differnces between Ada95 and C++
- Date: 27 Feb 1996 11:47:02 GMT
- Organization: Royal Melbourne Institute of Technology
- Distribution: world
- Message-ID: <4guqvm$4cn@goanna.cs.rmit.EDU.AU>
- References: <4gbq7q$g08@qualcomm.com> <4gt3ag$76m@druid.borland.com> <DnDuEG.8Kx@bton.ac.uk> <DnDuA4.8GC@bton.ac.uk>
- NNTP-Posting-Host: obibicut.cs.rmit.edu.au
- Mime-Version: 1.0
- Content-Type: text/plain; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: Nuntius 2.0.4_68K
- X-XXMessage-ID: <AD593B61D5011B17@obibicut.cs.rmit.edu.au>
- X-XXDate: Tue, 27 Feb 1996 06:51:13 GMT
-
- John English, je@bton.ac.uk writes:
- ": If what you say was the case, then types defined in package "A"
- : will be seen by clients to a package "B" where "B" has with'ed A. But
- : it is not so. Clients of "B" must also 'with' "A" to see types
- defined
- : in "A" even though "B: has allready with'ed "A".
-
- If you're right this would be a real pain. Clients of a package would
- have
- to know (recursively) what other packages the spec(s) reference; if the
- spec for X "withs" a package Y so it can use type Y.T as a procedure
- parameter then you wouldn't be able to use X without Y (i.e. "with X"
- on its own would be useless; you'd have to have "with X, Y" and
- probably
- other things as well if Y has any "with" clauses in its specification.
-
- This is such a horrible concept that I'm inclined to believe GNAT, but
- if anyone who can understand all the subleties of the visibility rules
- can give us all a definitive explanation in words of sufficiently few
- syllables that Bears of Very Little Brain like me can understand, I for
- one would be profoundly grateful."
-
- Au Contraire, it's a great concept. It is SO nice to be able to see,
- from the top of a listing, just what the relationship b/w the unit
- you are looking at to the rest of the system is.
-
- I *hate* transtive 'with'ing relationships! When you read the code
- of C/C++, you may have one #include at the top, but your code
- references
- all sorts of types/functions etc. Where do they come from? What range
- of packages do I have to look at before I can find the declarations?
- Should I do a broad search, or a depth first search on the #include
- files
- when looking for the declarations?
- In Ada, with it's 'flat' view of 'with'ings (compared to C's deep
- #include
- model) you can easily see the level of coupling of a
- package/compilation
- unit.
-
- A simple explanation is perhaps...
-
- "with"ing never extends beyond the units you have explicity "with"ed.
- If you need something that they have "with"ed, then you have to
- with it as well. "With"ing is only ever one unit deep.
-
- A simple example
- ----------------------------------
- package a is
- type alpha is...
-
- function X return alpha;
- end a;
-
- ----------------------------------
- with a;
- package b is
- type beta is
-
- procedure Y(item: alpha);
- procedure Z(item:in out beta);
- end b;
-
- ----------------------------------
- -- if you use resources from A, -- If you don't use resources from
- -- then you have to "with" A. -- A, then you can ignore it.
- with A;
- with B; with B;
-
- procedure main is procedure main is
- stuff :A.alpha := A.X; stuff :B.beta;
- begin begin
- B.Y(stuff); B.Z(stuff);
- end; end;
-
- Important to note that if procedure main isn't going to declare any
- alpha values, or call B.Y, then it doesn't need to with A at all.
-
- The fact that B has "with"ed A can be viewed as a compositional
- legacy from the construction of B. It has little to do with how
- procedure main is constructed.
-
- If "main" want's to use resources from A, then it explicity has to
- declare it's intent for all the world to see.
-
- The use clause only means you don't have to use dot notation (e.g.
- B.Y) when accessing resources from the package.
-
- I suspect that if you examine some real code that you will not
- find too great a list of "with"ed units (esp. with well designed
- code). Even if it were, I wouldn't be too concerned, as it aids
- the reader of the code.
-
-
- Dale
-